package vip.youngboy.freejump.handler.task;

import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
import vip.youngboy.freejump.constant.TaskActionType;
import vip.youngboy.freejump.domain.FlowRequestParam;
import vip.youngboy.freejump.domain.TaskActionModel;
import vip.youngboy.freejump.domain.process.Option;

import java.util.List;

/**
 * 驳回，按流程图连线走,前台传指定的流程变量控制流转
 */
@Component
public class TaskRejectActionHandler extends AbstractTaskActionHandler {

    @Override
    public void doHandleAction(TaskActionModel taskActionModel) {
        //执行驳回逻辑
        String taskId = taskActionModel.getFlowRequestParam().getTaskId();
        String assign = taskActionModel.getAssign();
        taskService.claim(taskId, assign);
        taskService.complete(taskId, taskActionModel.getFlowRequestParam().getVariables());
    }

    @Override
    public void vaildOptions(FlowRequestParam flowRequestParam) {
        Assert.notEmpty(flowRequestParam.getVariables(), "流程变量不能为空");
        Assert.notNull(flowRequestParam.getOpinion(), "驳回意见不能为空");
    }

    @Override
    public TaskActionType supportAction() {
        return TaskActionType.REJECT;
    }

    @Override
    public List<Option> getOptions() {
        return null;
    }

}
